package com.androidexample.ftpdemo;

import java.io.File;

import com.kpbird.ftpdemo.R;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

public class FTP_Ex2 extends Activity {

	Button ocmConnect, ocmGetDirectory, ocmUpload, ocmDownload, ocmUseImg;
	String tDirec;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.wex2);

		ocmConnect = (Button) findViewById(R.id.ocmConnect);
		ocmGetDirectory = (Button) findViewById(R.id.ocmGetDirectory);
		ocmUpload = (Button) findViewById(R.id.ocmUpload);
		ocmDownload = (Button) findViewById(R.id.ocmDownload);
		ocmUseImg = (Button) findViewById(R.id.ocmUseImg);

		ocmConnect.setOnClickListener(new View.OnClickListener() {

			public void onClick(View v) {
				// TODO Auto-generated method stub
				Log.d("Button", "You Clicked");
				boolean bCheckconnect = Ex2.ftpConnect("192.168.0.242",
						"anonymous", "", 21);
				Log.d("connected", String.valueOf(bCheckconnect));
			}
		});

		ocmGetDirectory.setOnClickListener(new View.OnClickListener() {

			public void onClick(View v) {
				// TODO Auto-generated method stub
				tDirec = Ex2.ftpGetCurrentWorkingDirectory();
				Log.d("Directory", tDirec);
			}
		});

		ocmUpload.setOnClickListener(new View.OnClickListener() {

			public void onClick(View v) {
				// TODO Auto-generated method stub
				// ftp.ftpPrintFilesList(tDirec);
				String srcFilePath = Environment.getExternalStorageDirectory()
						.getAbsolutePath() + "/bixolon.jpg";
				String desFileName = "bixolon.jpg";
				// String desDirectory = tDirec;
				boolean bStatus = Ex2.ftpUpload(srcFilePath, desFileName);
				Log.d("Upload", String.valueOf(bStatus));
			}
		});

		ocmDownload.setOnClickListener(new View.OnClickListener() {

			public void onClick(View v) {
				// TODO Auto-generated method stub
				Ex2.ftpPrintFilesList(tDirec);
				String desFilePath = Environment.getExternalStorageDirectory()
						.getAbsolutePath() + "/image3.PNG";
				String srcFilePath = Ex2.ftpGetCurrentWorkingDirectory()
						+ "Ram.PNG";
				Log.d("Download log...", "src = " + srcFilePath
						+ "\r\ndesFilePath = " + desFilePath);
				boolean bStatusDL = Ex2.ftpDownload(srcFilePath, desFilePath);
				Log.d("Download", String.valueOf(bStatusDL));
			}
		});

		ocmUseImg.setOnClickListener(new View.OnClickListener() {

			public void onClick(View v) {////
				// TODO Auto-generated method stub
				String tUseImg = Environment.getExternalStorageDirectory()
						.getAbsolutePath() + "/image3.PNG";
				Log.d("Path", tUseImg);

				Bitmap myBitmap = BitmapFactory.decodeFile(tUseImg);

				ImageView myImage = (ImageView) findViewById(R.id.oivImg);
				myImage.setImageBitmap(myBitmap);

			}
		});
	}

}
